/**
 * Created by LeungZ on 2016/9/18.
 */
class ImageSrv {
    constructor(commonSrv) {
        "ngInject";
        this._commonSrv = commonSrv;
    }

    getImageList(page, filter) {
        return this._commonSrv('get', '/ctg-imageconsole-web/imageRepository/queryImageList', {
            pageSize: page.page || 10,
            pageNum: page.currentPage,
            imageName: filter && filter.imageName,
            imageType: filter && filter.imageType
        });
    }
    //管理员接口
    isAdmin(){
        return this._commonSrv('get','/ctg-imageconsole-web/users/isAdmin',{
        })
    }
    getImageDetail(para) {
        return this._commonSrv('get', '/ctg-imageconsole-web/imageRepository/queryImageInfo', {
            imageFileId: para.id
        });
    }

    // getImageVers(para) {
    //     return this._commonSrv('get', '/ctg-imageconsole-web/imageRepository/queryPerVersionByImageId', {
    //         imageFileId: para.id,
    //         pageSize: para.page || 10,
    //         pageNum: para.currentPage
    //     });
    // }

    getImageVers(imageName,imageType) {
        return this.getHarborVersions(imageName,imageType);
    }

    // 我的镜像20170421 by Luji
    getHarborImages(para){
        return this._commonSrv('get', '/ctg-imageconsole-web/image/repositories', {
            pageSize: para.page || 10,
            pageNum: para.currentPage,
            imageType:para.imageType,
            sysUserCode:para.sysUserCode
        });
    }

    getHarborVersions(imageName,imageType){
        return this._commonSrv('get', '/ctg-imageconsole-web/image/repository/tags', {
            imageName: imageName,
            imageType:imageType
        });
    }
    //镜像共享
    shareImage(para){
        return this._commonSrv('post','/ctg-imageconsole-web/image/repository/tag/share',para);
    }
    //获取已共享的用户
    getShareImage(para){
        return this._commonSrv('get','/ctg-imageconsole-web/image/repository/tag/share',para);
    }
    //配置管理
    getConfigList(para){
        return this._commonSrv('get', '/ctg-imageconsole-web/config/queryImageConfigList', {
            dockerImageTagId: para.id,
            pageSize: para.page || 10,
            pageNum: para.currentPage
        });
    }
    getsearchList(para){
        return this._commonSrv('get', '/ctg-imageconsole-web/config/queryImageConfigByName', {
            config_name: para.configName,
            dockerImageTagId:para.dockerImageTagId,
            pageSize: para.page || 10,
            pageNum: para.currentPage?para.currentPage:1
        });
    }
    //添加配置文件
      addConfig(para){
        return this._commonSrv('post', '/ctg-imageconsole-web/config/addImageConfig', para);
    }
      editConfig(para){
        return this._commonSrv('post', '/ctg-imageconsole-web/config/updateImageConfig', para);
    }
      deleteConfig(para){
        return this._commonSrv('get', '/ctg-imageconsole-web/config/delImageConfig', para);
    }
      checkVersion(para){
        return this._commonSrv('get', '/ctg-imageconsole-web/config/checkImageConfigVersion', para);
    }
      getConfigName(para){
        return this._commonSrv('get', '/ctg-imageconsole-web/config/queryImageConfigNameByImageId', para);
    }
      getConfigVer(para){
        return this._commonSrv('get', '/ctg-imageconsole-web/config/queryImageConfigVersion', para);
    }
      getConfigsData(para){
        return this._commonSrv('get', '/ctg-imageconsole-web/config/queryImageConfigByVersion', para);
    }

    editHarborVersions(param){
        return this._commonSrv('post', '/ctg-imageconsole-web/image/repository/tag/edit', {
            imageFileId: param.imageFileId,
            imageIndexId: param.imageIndexId,
            imageName: param.imageName,
            servicePort: param.servicePort,
            version: param.version,
        });
    }
}
export default ImageSrv